package com.cykj.web.controller.posbiz;

import com.cykj.common.annotation.Log;
import com.cykj.common.core.controller.BaseController;
import com.cykj.common.core.domain.AjaxResult;
import com.cykj.common.core.page.TableDataInfo;
import com.cykj.common.enums.BusinessType;
import com.cykj.common.utils.poi.ExcelUtil;
import com.cykj.pos.domain.BizAgentInformation;
import com.cykj.pos.service.IBizAgentInformationService;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

/**
 * 代理信息Controller
 *
 * @author weijianbo
 * @date 2021-09-01
 */
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/pos/information" )
public class BizAgentInformationController extends BaseController {

    private final IBizAgentInformationService iBizAgentInformationService;

    /**
     * 查询代理信息列表
     */
    @PreAuthorize("@ss.hasPermi('pos:information:list')")
    @GetMapping("/list")
    public TableDataInfo list(BizAgentInformation bizAgentInformation) {
        startPage();
        List<BizAgentInformation> list = iBizAgentInformationService.queryList(bizAgentInformation);
        return getDataTable(list);
    }

    /**
     * 导出代理信息列表
     */
    @PreAuthorize("@ss.hasPermi('pos:information:export')" )
    @Log(title = "代理信息" , businessType = BusinessType.EXPORT)
    @GetMapping("/export" )
    public AjaxResult export(BizAgentInformation bizAgentInformation) {
        List<BizAgentInformation> list = iBizAgentInformationService.queryList(bizAgentInformation);
        ExcelUtil<BizAgentInformation> util = new ExcelUtil<BizAgentInformation>(BizAgentInformation.class);
        return util.exportExcel(list, "information" );
    }

    /**
     * 获取代理信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('pos:information:query')" )
    @GetMapping(value = "/{agentId}" )
    public AjaxResult getInfo(@PathVariable("agentId" ) Long agentId) {
        return AjaxResult.success(iBizAgentInformationService.getById(agentId));
    }

    /**
     * 新增代理信息
     */
    @PreAuthorize("@ss.hasPermi('pos:information:add')" )
    @Log(title = "代理信息" , businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BizAgentInformation bizAgentInformation) {
        return toAjax(iBizAgentInformationService.save(bizAgentInformation) ? 1 : 0);
    }

    /**
     * 修改代理信息
     */
    @PreAuthorize("@ss.hasPermi('pos:information:edit')" )
    @Log(title = "代理信息" , businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BizAgentInformation bizAgentInformation) {
        return toAjax(iBizAgentInformationService.updateById(bizAgentInformation) ? 1 : 0);
    }

    /**
     * 删除代理信息
     */
    @PreAuthorize("@ss.hasPermi('pos:information:remove')" )
    @Log(title = "代理信息" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{agentIds}" )
    public AjaxResult remove(@PathVariable Long[] agentIds) {
        return toAjax(iBizAgentInformationService.removeByIds(Arrays.asList(agentIds)) ? 1 : 0);
    }
}
